home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / c01lab4.zip / LRMRDR / LRM_CHAP.ZIP / CHAP08.DOC < prev    next >
Text File  |  1992-04-21  |  39KB  |  855 lines

  1. >                             8. Visibility Rules
  2.  
  3.  
  4. The  rules  defining the scope of declarations and the rules defining which
  5. identifiers are visible at various points in the text of  the  program  are
  6. described  in this chapter.  The formulation of these rules uses the notion
  7. of a declarative region.
  8.  
  9.  
  10. References:  declaration 3.1, declarative region 8.1, identifier 2.3, scope
  11. 8.2, visibility 8.3
  12.  
  13. > 8.1  Declarative Region
  14.  
  15.  
  16. A  declarative  region  is  a  portion  of  the  program  text.   A  single
  17. declarative region is formed by the text of each of the following:
  18.  
  19.  
  20.   -  A subprogram declaration, a package declaration, a  task  declaration,
  21.      or  a  generic  declaration,  together with the corresponding body, if
  22.      any.  If the body is a body stub, the declarative region also includes
  23.      the corresponding subunit.  If the program unit has subunits, they are
  24.      also included.
  25.  
  26.  
  27.   -  An  entry  declaration  together   with   the   corresponding   accept
  28.      statements.
  29.  
  30.  
  31.   -  A record type declaration, together with a  corresponding  private  or
  32.      incomplete  type declaration if any, and together with a corresponding
  33.      record representation clause if any.
  34.  
  35.  
  36.   -  A renaming declaration that includes  a  formal  part,  or  a  generic
  37.      parameter  declaration  that  includes  either  a  formal  part  or  a
  38.      discriminant part.
  39.  
  40.  
  41.   -  A block statement or a loop statement.
  42.  
  43.  
  44. In each of the above cases, the declarative region is said to be associated
  45. with the corresponding declaration or statement.  A declaration is said  to
  46. occur  immediately  within  a  declarative  region  if  this  region is the
  47. innermost  region  that  encloses  the  declaration,   not   counting   the
  48. declarative region (if any) associated with the declaration itself.
  49.  
  50.  
  51. A  declaration  that occurs immediately within a declarative region is said
  52. to be local to the region.  Declarations in outer (enclosing)  regions  are
  53. said  to  be  global  to  an  inner (enclosed) declarative region.  A local
  54. entity is one declared by a local declaration;   a  global  entity  is  one
  55. declared by a global declaration.
  56.  
  57.  
  58. Some  of  the  above  forms  of declarative region include several disjoint
  59. parts (for example, other declarative items can be between the  declaration
  60. of  a  package  and  its  body).   Each  declarative region is nevertheless
  61. considered as a (logically) continuous portion of the program text.   Hence
  62. if  any  rule defines  a portion of text as the text that extends from some
  63. specific point of a declarative region to the end of this region, then this
  64. portion is the corresponding subset of the declarative region (for  example
  65. it does not include intermediate declarative items between the two parts of
  66. a package).
  67.  
  68. Notes:
  69.  
  70.  
  71. As   defined   in   section   3.1,  the  term  declaration  includes  basic
  72. declarations, implicit declarations, and those declarations that  are  part
  73. of   basic   declarations,   for   example,   discriminant   and  parameter
  74. specifications.  It follows from the definition  of  a  declarative  region
  75. that  a  discriminant  specification  occurs  immediately within the region
  76. associated with  the  enclosing  record  type  declaration.   Similarly,  a
  77. parameter  specification  occurs  immediately  within the region associated
  78. with the enclosing subprogram body or accept statement.
  79.  
  80.  
  81. The package STANDARD forms a declarative region which encloses all  library
  82. units:   the  implicit declaration of each library unit is assumed to occur
  83. immediately within this package (see sections 8.6 and 10.1.1).
  84.  
  85.  
  86. Declarative regions can be nested within other  declarative  regions.   For
  87. example,  subprograms,  packages,  task  units,  generic  units,  and block
  88. statements can be nested within each other, and  can  contain  record  type
  89. declarations, loop statements, and accept statements.
  90.  
  91.  
  92. References:   accept  statement 9.5, basic declaration 3.1, block statement
  93. 5.6, body stub 10.2, declaration 3.1, discriminant part 3.7.1, discriminant
  94. specification 3.7.1, entry declaration 9.5, formal part 6.1,  generic  body
  95. 12.2,   generic  declaration  12.1,  generic  parameter  declaration  12.1,
  96. implicit declaration 3.1, incomplete type declaration 3.8.1,  library  unit
  97. 10.1,  loop statement 5.5, package 7, package body 7.1, package declaration
  98. 7.1, parameter specification 6.1,  private  type  declaration  7.4,  record
  99. representation  clause  13.4,  record  type  3.7, renaming declaration 8.5,
  100. standard package 8.6, subprogram  body  6.3,  subprogram  declaration  6.1,
  101. subunit 10.2, task body 9.1, task declaration 9.1, task unit 9
  102.  
  103. > 8.2  Scope of Declarations
  104.  
  105.  
  106. For  each  form of declaration, the language rules define a certain portion
  107. of the program text called the scope of the declaration.  The  scope  of  a
  108. declaration  is  also  called  the  scope  of  any  entity  declared by the
  109. declaration.  Furthermore, if the declaration associates some notation with
  110. a declared entity, this portion of the text is also  called  the  scope  of
  111. this  notation  (either  an  identifier,  a  character literal, an operator
  112. symbol, or the notation for a basic operation).  Within  the  scope  of  an
  113. entity,  and  only  there,  there  are  places where it is legal to use the
  114. associated notation in order to refer to the declared entity.  These places
  115. are defined by the rules of visibility and overloading.
  116.  
  117.  
  118. The scope of a declaration that occurs  immediately  within  a  declarative
  119. region  extends  from  the  beginning  of the declaration to the end of the
  120. declarative region;  this part of the scope of a declaration is called  the
  121. immediate  scope.   Furthermore,  for any of the declarations listed below,
  122. the scope of the declaration extends beyond the immediate scope:
  123.  
  124.  
  125. (a)  A declaration that occurs immediately within the  visible  part  of  a
  126.      package declaration.
  127.  
  128.  
  129. (b)  An entry declaration.
  130.  
  131.  
  132. (c)  A component declaration.
  133.  
  134.  
  135. (d)  A discriminant specification.
  136.  
  137.  
  138. (e)  A parameter specification.
  139.  
  140.  
  141. (f)  A generic parameter declaration.
  142.  
  143.  
  144. In  each  of  these  cases, the given declaration occurs immediately within
  145. some enclosing declaration, and the scope of the given declaration  extends
  146. to the end of the scope of the enclosing declaration.
  147.  
  148.  
  149. In  the  absence  of a subprogram declaration, the subprogram specification
  150. given in the subprogram body or in the body stub acts  as  the  declaration
  151. and rule (e) applies also in such a case.
  152.  
  153. Note:
  154.  
  155.  
  156. The  above scope rules apply to all forms of declaration defined by section
  157. 3.1;  in particular, they apply also to implicit  declarations.   Rule  (a)
  158. applies  to a package declaration and thus not to the package specification
  159. of a generic declaration.  For nested declarations, the rules  (a)  through
  160. (f)  apply  at  each level.  For example, if a task unit is declared in the
  161. visible part of a package, the scope of an entry of the task  unit  extends
  162. to  the end of the scope of the task unit, that is, to the end of the scope
  163. of the enclosing package.  The scope of a use clause is defined in  section
  164. 8.4.
  165.  
  166.  
  167. References:   basic operation 3.3.3, body stub 10.2, character literal 2.5,
  168. component  declaration  3.7,  declaration  3.1,  declarative  region   8.1,
  169. discriminant  specification  3.7.1,  entry  declaration  9.5,  extends 8.1,
  170. generic declaration 12.1, generic parameter  declaration  12.1,  identifier
  171. 2.3,  implicit  declaration  3.1,  occur  immediately  within 8.1, operator
  172. symbol  6.1,  overloading  6.6  8.7,  package  declaration   7.1,   package
  173. specification  7.1,  parameter specification 6.1, record type 3.7, renaming
  174. declaration 8.5, subprogram body  6.3,  subprogram  declaration  6.1,  task
  175. declaration  9.1,  task  unit  9,  type  declaration 3.3.1, use clause 8.4,
  176. visibility 8.3, visible part 7.2
  177.  
  178. > 8.3  Visibility
  179.  
  180.  
  181. The meaning of the occurrence of an identifier at a given place in the text
  182. is defined by the visibility rules and also,  in  the  case  of  overloaded
  183. declarations, by the overloading rules.  The identifiers considered in th